<?php

/**
 * This is the model class for table "comment".
 *
 * The followings are the available columns in table 'comment':
 * @property integer $com_code
 * @property string $com_name
 * @property string $com_email
 * @property integer $com_content
 * @property string $com_date
 * @property integer $ble_code
 *
 * The followings are the available model relations:
 * @property BlogEntry $bleCode
 */
class Comment extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Comment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'comment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('com_content,com_name,com_email', 'required'),
			array('ble_code', 'numerical', 'integerOnly'=>true),
			array('com_name, com_email, com_content', 'length', 'max'=>145),
			array('com_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('com_code, com_name, com_email, com_content, com_date, ble_code', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'bleCode' => array(self::BELONGS_TO, 'BlogEntry', 'ble_code'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'com_code' => 'Com Code',
			'com_name' => 'Com Name',
			'com_email' => 'Com Email',
			'com_content' => 'Com Content',
			'com_date' => 'Com Date',
			'ble_code' => 'Ble Code',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('com_code',$this->com_code);
		$criteria->compare('com_name',$this->com_name,true);
		$criteria->compare('com_email',$this->com_email,true);
		$criteria->compare('com_content',$this->com_content);
		$criteria->compare('com_date',$this->com_date,true);
		$criteria->compare('ble_code',$this->ble_code);
		
		$blog = (int)$_GET['blogentry'];
    if($blog > 0){
          $criteria->condition = 'ble_code='.$blog;
      }else{
          throw new CHttpException(404, 'The requested page does not exist.');
      }

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function behaviors()
  {
      return array('datetimeI18NBehavior' => array('class' => 'ext.DateTimeI18NBehavior')); // 'ext' is in Yii 1.0.8 version. For early versions, use 'application.extensions' instead.
  }
}